<div>
  <!--面包屑  -->
  <el-breadcrumb class="bread" separator-class="el-icon-arrow-right">
    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    <el-breadcrumb-item>用户列表</el-breadcrumb-item>
  </el-breadcrumb>

  <!--  文本框 查询参数
    slot 改变搜索图标的方向 append(后面) prepend(前面)
    :gutter="20"  列与列之间的间隔  栅格间隔
  -->
  <el-row :gutter="20">
    <el-col :span="8">
      <el-input placeholder="请输入内容" v-model="searchText">
        <el-button
          @click="startQuery"
          slot="append"
          icon="el-icon-search"
        ></el-button>
      </el-input>
    </el-col>
    <el-col :span="3">
      <el-button @click="showAddUserDialog">添加用户</el-button>
    </el-col>
  </el-row>

  <!-- 表格 -->
  <!--
    el-table 表格
     data : 表格数据

   el-table-column 列  => 标签组件显示死的
   行数  => tabelData 数组里的元素个数觉得
  -->
  <el-table :data="usersData" style="width: 100%">
    <el-table-column prop="username" label="姓名" width="180"></el-table-column>
    <el-table-column prop="email" label="邮箱" width="180"></el-table-column>
    <el-table-column prop="mobile" label="电话"></el-table-column>
    <el-table-column label="用户状态">
      <template slot-scope="scope">
        <el-switch
          @change="stateChanged(scope.row)"
          v-model="scope.row.mg_state"
        ></el-switch>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <!--
          type : 设置颜色 primary蓝色 success绿色 danger红色
          plain : 镂空 (外面一圈有颜色 里面空白)
          size : 尺寸  mini 小
        -->
        <!-- 编辑 -->
        <el-button
          @click="showEditUserDialog(scope.row)"
          size="mini"
          plain
          type="primary"
          icon="el-icon-edit"
        ></el-button>
        <!-- 删除 -->
        <el-button
          @click="delUser(scope.row.id)"
          size="mini"
          plain
          type="danger"
          icon="el-icon-delete"
        ></el-button>
        <el-button
          @click="showAssignRoleDialog(scope.row)"
          size="mini"
          plain
          type="success"
          icon="el-icon-check"
          >分配角色</el-button
        >
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <!--
     :current-page="1"  当前页
     :page-size="2"   每页个数
     :total="5"     总个数
  -->
  <el-pagination
    @current-change="changeCurPage"
    :page-size="2"
    :current-page="pagenum"
    :total="total"
    background
    layout="prev, pager, next"
  ></el-pagination>

  <!-- 第一个对话框 : 添加用户 -->
  <el-dialog
    @closed="dialogClosed"
    title="添加用户"
    :visible.sync="dialogAddUserVisible"
  >
    <el-form
      ref="addUserRef"
      :model="addUserForm"
      label-width="80px"
      :rules="rules"
    >
      <el-form-item label="用户名" prop="username">
        <el-input v-model="addUserForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="addUserForm.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="addUserForm.email"></el-input>
      </el-form-item>
      <el-form-item label="手机" prop="mobile">
        <el-input v-model="addUserForm.mobile"></el-input>
      </el-form-item>
    </el-form>

    <div slot="footer">
      <el-button @click="dialogAddUserVisible = false">取 消</el-button>
      <el-button type="primary" @click="addUser">确 定</el-button>
    </div>
  </el-dialog>

  <!-- 第二个对话框 : 编辑用户 -->
  <el-dialog title="编辑用户" :visible.sync="dialogEditUserVisible">
    <el-form :model="editUserForm" label-width="80px">
      <el-form-item label="用户名">
        <el-tag type="info">{{ editUserForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="邮箱">
        <el-input v-model="editUserForm.email"></el-input>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="editUserForm.mobile"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogEditUserVisible = false">取 消</el-button>
      <el-button type="primary" @click="editUser">确 定</el-button>
    </div>
  </el-dialog>

  <!-- 第三个对话框 : 分配角色 -->
  <el-dialog title="分配角色" :visible.sync="dialogAssignRoleVisible">
    <el-form :model="assignRoleForm" label-width="100px">
      <el-form-item label="用户名">
        <!-- <el-input v-model="assignRoleForm.username"></el-input> -->
        <el-tag>{{ assignRoleForm.username }}</el-tag>
      </el-form-item>
      <el-form-item label="角色列表">
        <el-select v-model="assignRoleForm.rid" placeholder="请选择角色">
          <!-- label 负责显示的  value 是收集数据的 -->
          <el-option
            v-for="item in rolesList"
            :key="item.id"
            :label="item.roleName"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogAssignRoleVisible = false">取 消</el-button>
      <el-button type="primary" @click="assignRole">确 定</el-button>
    </div>
  </el-dialog>
</div>
